package common.message;

import java.io.Serializable;

public abstract class Message implements Serializable {
	
	private static final long serialVersionUID = -7551290843770394L;
	
	private String from;
	private String to;
	
	public static final String getServerFlag() { return "server"; }
	public static final String getUserFlag() {  return "user #"; }
	
	public Message(String from, String to) {
		super();
		this.from = from;
		this.to = to;
	}
	
	public String getFrom() { return from; }
	public boolean fromServer() { return from == getServerFlag(); }
	public boolean fromUser() { return getFromUserID() != -1; }
	public int getFromUserID() {
		if (from.startsWith(getUserFlag()))
			return Integer.parseInt(from.substring(getUserFlag().length(), from.length()));
		else
			return -1;
	}

	public void setFrom(String from) { this.from = from; }

	public String getTo() { return to; }
	public boolean toServer() { return to == getServerFlag(); }
	public boolean toUser() { return getToUserID() != -1; }
	public int getToUserID() {
		if (to.startsWith(getUserFlag()))
			return Integer.parseInt(to.substring(getUserFlag().length(), to.length()));
		else
			return -1;
	}

	public void setTo(String to) { this.to = to; }


}

